﻿using K9Nano.Events;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace AllInOneApiTest.Events
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class EventController : ControllerBase
    {
        private readonly ILogger<EventController> _logger;
        private readonly IEventBus _eventBus;

        public EventController(ILogger<EventController> logger, IEventBus eventBus)
        {
            _logger = logger;
            _eventBus = eventBus;
        }

        [HttpGet]
        public string Trigger(bool async, string value)
        {
            if (async)
            {
                _eventBus.Trigger(new EventAsyncTestData(value, this.GetType().FullName));
            }
            else
            {
                _eventBus.Trigger(new EventTestData(value, this.GetType().FullName));
            }

            return "Ok";
        }
    }
}
